package com.wiegand.util {

	/**
	 * @author gandy
	 */
	public class ExtendedArray {

		private var _names : Array;
		private var _objects : Array;

		public function ExtendedArray(){
			_names=new Array();
			_objects=new Array();
		}
		
		public function add(object:Object,name:String):void{
			_objects.push(object);
			_names.push(name);
		}

		public function getIndexByName(name:String):int{
			var index : int = -1;
			for(var i : int = 0; i<_names.length; i++){
				if(_names[i]==name) index=i;
			}
			return index;
		}

		public function getIndexByObject(object:Object):int{
			var index : int = -1;
			for(var i : int = 0; i<_objects.length; i++){
				if(_objects[i]==object) index=i;
			}
			return index;
		}
		
		public function get length():int{
			return _objects.length;
		}
		
		public function getObjectByIndex(index:int):Object{
			return _objects[index];
		}
		
		public function getObjectByName(name:String):Object{
			return _objects[getIndexByName(name)];
		}
		
		public function removeByName(name:String):void{
			var index : int = getIndexByName(name);
			_objects.splice(index,1);
			_names.splice(index,1);
		}
		
		public function removeByObject(object:Object):void{
			var index : int = getIndexByObject(object);
			_objects.splice(index,1);
			_names.splice(index,1);
		}
		
		public function toString():String{
			var str : String = "ExtendedArray ("+_objects.length+"): ";
			for(var i : int = 0; i<_objects.length; i++){
				str += String(" " + _names[i]);
			}
			return str;
		}
		
	}
}
